package cn.yunchongbao.charging.order.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqttProducer {
    @Autowired
    private MqttClient  mqttClient;
    public void send(String topic,String message){
        try {
            mqttClient.publish(topic,message.getBytes(),0,true);
        } catch (MqttException e) {
            throw new RuntimeException(e);
        }
    }
}
